#include "glutKeboardManager.h"

#include <iostream> ///////////////************************ remove at some point
#include <GL\glut.h>


char* glutKeboardManager::_state = new char[KEYBOARD_SIZE];

///Main update function used to check for single key presses
// this will alow the user to check for if it was the first tap of the key
// or was midway through the press
void glutKeboardManager::update()
{
	for(int i = 0; i < KEYBOARD_SIZE; i++)
	{
		if(_state[i] == FIRST_PRESS)
		{
			_state[i] =	HELD_DOWN;
		}
	}
}

// checks to see if the key pased in is pressed and returns its state
bool glutKeboardManager::KeyPresed(unsigned char key)
{
	if(_state[key] == FIRST_PRESS || _state[key] == HELD_DOWN)
	{
		return true;
	}
	return false;
}
// checks to see if the key pased in has just been pressed it returns true if just presed
bool glutKeboardManager::FirstPress(unsigned char key)
{
	if(_state[key] == FIRST_PRESS)
	{
		return true;
	}
	return false;
}

// key down function
void glutKeboardManager::keyDown(unsigned char key, int x, int y)
{
	//std::cout << "Key presed: " << (char)key << std::endl;
	//int iVal = key;
	//std::cout << "Int Value: " << iVal << std::endl;
	_state[key] = FIRST_PRESS;
}
// key up function
void glutKeboardManager::keyUp(unsigned char key, int x, int y)
{
	//std::cout << "Key Released: " << (char)key << std::endl;
	_state[key] = NOT_PRESSED;
}

// sets up the keyboard manager to listen to the corect things
void glutKeboardManager::begin()
{
	glutIgnoreKeyRepeat(true);
	glutKeyboardFunc(keyDown);
	glutKeyboardUpFunc(keyUp);

}
